﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace QuanLyDuocPham.View.QuanLyCauHinh.NguoiDung
{
    /// <summary>
    /// Interaction logic for USER_Edit_View.xaml
    /// </summary>
    public partial class USER_Edit_View : Window
    {
        public USER_Edit_View()
        {
            InitializeComponent();
        }
        public delegate void added();
        public added done;

        string ma_nv;

        public string _ma_nv
        {
            set
            {
                ma_nv = value;
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            userctrl.loadUSER_Edit(ma_nv, txtHo_Ten, txtTen_DN, txtMat_Khau, cmbNhomND, chbTRANG_THAI);
        }
        Controllers.QuanLyCauHinh.NguoiDung.NHOMND_Control nhomndctrl = new Controllers.QuanLyCauHinh.NguoiDung.NHOMND_Control();
        private void cmbNhomND_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var a = (NHOMND_Get_ListResult)cmbNhomND.SelectedItem;
            if (a != null && a.DIEN_GIAI == "Thêm mới")
            {
                View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View nhomndview = new View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View();
                nhomndview.ShowDialog();
                nhomndctrl.loadComboBox(cmbNhomND);
            }
        }
        Controllers.QuanLyCauHinh.NguoiDung.USER_Control userctrl = new Controllers.QuanLyCauHinh.NguoiDung.USER_Control();
        private void btOk_Click(object sender, RoutedEventArgs e)
        {
            if ( (txtTen_DN.Text.Trim() != "" ) || (txtMat_Khau.Password.Trim() != "") || (cmbNhomND.SelectedItem != null))
            {
                userctrl.updateData(ma_nv, txtTen_DN, txtMat_Khau,cmbNhomND, chbTRANG_THAI);
                if (done != null)
                {
                    done();
                }
            }
            else
            {
                MessageBox.Show("Dữ liệu không hợp lệ");
            }
        }

        private void btBack_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void cmbNhomND_KeyDown(object sender, KeyEventArgs e)
        {
            cmbNhomND.IsDropDownOpen = true;

        }


        
    }
}
